package com.luguotao.lease.web.custom.config;

import com.luguotao.lease.web.custom.converter.StringToBaseEnumConverterFactory;
import com.luguotao.lease.web.custom.converter.StringToItemTypeConverter;
import com.luguotao.lease.web.custom.interceptor.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


//注册converter
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
//    @Autowired
//    StringToItemTypeConverter converter;
    @Autowired
    StringToBaseEnumConverterFactory factory;
    @Autowired
    AuthenticationInterceptor authenticationInterceptor;

    @Override
    //为什么是格式化？我的理解是对后端来说，相当于把前端的格式转化的一个工具
    public void addFormatters(FormatterRegistry registry) {
//        registry.addConverter(converter);
        registry.addConverterFactory(factory);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor).addPathPatterns("/admin/**").excludePathPatterns("/admin/login/**");
    }
}
